package com.pear.core.ctl;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 类<code>StringTools</code>提供了字符相关的便捷操作，若不确定是否满足要求可以测试某个方法是否符合要求。
 * <p><font color=red>注意：本类中的所有字符处理若没有特意指明进行trim，则默认全部是不进行trim，如需要则要主动调用trim方法进行去空格字符。</font></p>
 *
 * @author 顾晓健
 * @version %I%, %G%
 * @since 1.0
 */
public class StringTools {

    /**
     * <p>检查字符串是否为Null或者""。</p>
     * <pre><font color=green>
     * StringTools.isEmpty(null)      = true
     * StringTools.isEmpty("")        = true
     * StringTools.isEmpty(" ")       = false
     * StringTools.isEmpty("test")     = false
     * StringTools.isEmpty("  test  ") = false
     * </font></pre>
     *
     * @param str 待检查字符串，可能为NUll
     * @return 如果是Null或者""，则返回{@code true}；否则返回{@code false}
     */
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    /**
     * <p>检查字符串是否不为Null或者""。</p>
     * <pre><font color=green>
     * StringTools.isNotEmpty(null)      = false
     * StringTools.isNotEmpty("")        = false
     * StringTools.isNotEmpty(" ")       = true
     * StringTools.isNotEmpty("test")     = true
     * StringTools.isNotEmpty("  test  ") = true
     * </font></pre>
     *
     * @param str 待检查字符串，可能为NUll
     * @return 如果不是Null或者""，则返回{@code true}；否则返回{@code false}
     */
    public static boolean isNotEmpty(String str) {
        return !StringTools.isEmpty(str);
    }

    /**
     * <p>检查字符串是否为Null或者""或者" "。</p>
     * <pre><font color=green>
     * StringTools.isBlank(null)      = true
     * StringTools.isBlank("")        = true
     * StringTools.isBlank(" ")       = true
     * StringTools.isBlank("test")     = false
     * StringTools.isBlank("  test  ") = false
     * StringTools.isBlank("\t \n \f \r") = true //对于制表符、换行符、换页符和回车符
     * StringTools.isBlank("\b") = false //"\b"为单词边界符
     * </font></pre>
     *
     * @param str 待检查字符串，可能为NUll
     * @return 如果是Null或者""或者" "，则返回{@code true}；否则返回{@code false}
     */
    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }

        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串是否不为Null或者""或者" "。</p>
     * <pre><font color=green>
     * StringTools.isNotBlank(null)      = false
     * StringTools.isNotBlank("")        = false
     * StringTools.isNotBlank(" ")       = false
     * StringTools.isNotBlank("test")     = true
     * StringTools.isNotBlank("  test  ") = true
     * StringTools.isNotBlank("\t \n \f \r") = false
     * StringTools.isNotBlank("\b") = true
     * </font></pre>
     *
     * @param str 待检查字符串，可能为NUll
     * @return 如果不是Null或者""或者" "，则返回{@code true}；否则返回{@code false}
     */
    public static boolean isNotBlank(String str) {
        return !StringTools.isBlank(str);
    }

    /**
     * <p>去掉字符串两端的控制符。</p>
     * <pre><font color=green>
     * StringTools.trim(null)          = null
     * StringTools.trim("")            = ""
     * StringTools.trim("     ")       = ""
     * StringTools.trim("abc")         = "abc"
     * StringTools.trim("    abc    ") = "abc"
     * StringTools.trim(" \b \t \n \f \r ") = ""
     * StringTools.trim(" \n\tss \b") = "ss"
     * </font></pre>
     *
     * @param str 待去除两端控制符，可能为NUll
     * @return 去除两端控制符的字符串；如果字符串为空，则返回{@code null}
     */
    public static String trim(String str) {
        return str == null ? null : str.trim();
    }

    /**
     * <p>去掉数组中字符串两端的控制符。</p>
     * <pre><font color=green>
     * StringTools.trimAll(null)          = null
     * StringTools.trimAll("abc","","    abc    ")            = ["abc","","abc"]
     * </font></pre>
     *
     * @param strs 待去除两端控制符的字符串数组，可能为空数组或者NUll
     * @return 去除两端控制符的字符串数组；如果数组为Null或者空数组，则返回自身
     */
    public static String[] trimAll(String... strs) {
        int strsLen = strs.length;
        if (strs == null || strsLen == 0) {
            return strs;
        }

        String[] newArr = new String[strsLen];
        for (int i = 0; i < strsLen; i++) {
            newArr[i] = trim(strs[i]);
        }

        return newArr;
    }

    /**
     * <p>检查字符串是否为Null或者""，若是则返回默认字符串。</p>
     * <pre><font color=green>
     * StringTools.emptyToDefault(null,"default")          = default
     * StringTools.emptyToDefault("","default")            = default
     * StringTools.emptyToDefault("     ","default")       = "     "
     * StringTools.emptyToDefault("abc","default")         = "abc"
     * StringTools.emptyToDefault("    abc    ","default") = "    abc    "
     * StringTools.emptyToDefault(StringTools.trim("    abc    "),"default") = "abc"
     * </font></pre>
     *
     * @param str        待检查字符串
     * @param defaultStr 默认字符串
     * @return 如果不是Null或者""，则返回自己；否则返回指定的默认字符串
     */
    public static String emptyToDefault(String str, String defaultStr) {
        return isEmpty(str) ? defaultStr : str;
    }

    /**
     * <p>检查字符串是否为Null或者""或者" "，若是则返回默认字符串。</p>
     * <pre><font color=green>
     * StringTools.blankToDefault(null,"default")          = default
     * StringTools.blankToDefault("","default")            = default
     * StringTools.blankToDefault("     ","default")       = default
     * StringTools.blankToDefault("abc","default")         = "abc"
     * StringTools.blankToDefault("    abc    ","default") = "    abc    "
     * StringTools.blankToDefault(StringTools.trim("    abc    "),"default") = "abc"
     * </font></pre>
     *
     * @param str        待检查字符串
     * @param defaultStr 默认字符串
     * @return 如果不是Null或者""或者" "，则返回自己；否则返回指定的默认字符串
     */
    public static String blankToDefault(String str, String defaultStr) {
        return isBlank(str) ? defaultStr : str;
    }

    /**
     * <p>检查字符串是否相等，区分大小写。</p>
     * <pre><font color=green>
     * StringTools.equals(null,null) = true
     * StringTools.equals("abc", null) = false
     * StringTools.equals("abc", "ABC") = false
     * StringTools.equals("abc", "abc") = true
     * </font></pre>
     *
     * @param str1 字符串1，可能为Null
     * @param str2 字符串2，可能为Null
     * @return 如果字符串相等，则返回{@code true}，否则返回{@code false}
     */
    public static boolean equals(String str1, String str2) {
        return str1 == null ? str2 == null : str1.equals(str2);
    }

    /**
     * <p>检查字符串是否相等，不区分大小写。</p>
     * <pre><font color=green>
     * StringTools.equals(null,null) = true
     * StringTools.equals("abc", null) = false
     * StringTools.equals("abc", "ABC") = true
     * StringTools.equals("abc", "abc") = true
     * </font></pre>
     *
     * @param str1 字符串1，可能为Null
     * @param str2 字符串2，可能为Null
     * @return 如果不区分大小写时字符串相等，则返回{@code true}，否则返回{@code false}
     */
    public static boolean equalsIgnoreCase(String str1, String str2) {
        return str1 == null ? str2 == null : str1.equalsIgnoreCase(str2);
    }

    /**
     * <p>返回指定字符在字符串中第一次出现的位置。</p>
     * <pre><font color=green>
     * StringTools.indexOf("abc",'c') = 2
     * StringTools.indexOf("",'c') = -1
     * </font></pre>
     *
     * @param string     待查找字符串
     * @param searchChar 待搜索字符
     * @return 待搜索字符第一次出现位置；如果待查找字符串为Null或者""或者没有找到，则返回-1
     */
    public static int indexOf(String string, char searchChar) {
        return isEmpty(string) ? -1 : string.indexOf(searchChar, 0);
    }

    /**
     * <p>返回在字符串中指定位置处开始，指定字符第一次出现的位置。</p>
     * <pre><font color=green>
     * StringTools.indexOf("abcabcabc",'c',2) = 2
     * StringTools.indexOf("abcabcabc",'c',3) = 5
     * StringTools.indexOf("",'c',2) = -1
     * </font></pre>
     *
     * @param string     待查找字符串
     * @param searchChar 待搜索字符
     * @param start      字符查找的开始位置
     * @return 待搜索字符在指定位置处开始，第一次出现位置；如果待查找字符串为Null或者""或者没有找到，则返回-1
     */
    public static int indexOf(String string, char searchChar, int start) {
        return isEmpty(string) ? -1 : string.indexOf(searchChar, start);
    }

    /**
     * <p>返回指定字符串在字符串中第一次出现的位置。</p>
     * <pre><font color=green>
     * StringTools.indexOf("abc","bc") = 1
     * StringTools.indexOf("","bc") = -1
     * StringTools.indexOf("abc","") = 0
     * </font></pre>
     *
     * @param string       待查找字符串
     * @param searchString 待搜索字符串
     * @return 待搜索字符串第一次出现位置；如果待查找字符串为Null或者""或者没有找到，则返回-1
     */
    public static int indexOf(String string, String searchString) {
        return isEmpty(string) ? -1 : string.indexOf(searchString, 0);
    }

    /**
     * <p>返回在字符串中指定位置处开始，指定字符串第一次出现的位置。</p>
     * <pre><font color=green>
     * StringTools.indexOf("abcabcabc","bc",2) = 4
     * StringTools.indexOf("abcabcabc","bc",3) = 4
     * StringTools.indexOf("","bc",2) = -1
     * StringTools.indexOf("abcabcabc","",2) = 2
     * </font></pre>
     *
     * @param string       待查找字符串
     * @param searchString 待搜索字符串
     * @param start        字符串查找的开始位置
     * @return 待搜索字符串在指定位置处开始，第一次出现位置；如果待查找字符串为Null或者""或者没有找到，则返回-1
     */
    public static int indexOf(String string, String searchString, int start) {
        return isEmpty(string) ? -1 : string.indexOf(searchString, start);
    }

    /**
     * <p>在给定的长度内取得字符串的缩写，当字符串的长度小于给定的长度则返回原字符串。</p>
     * <p><font color=red>注意：长度不能小于4，否则抛出IllegalArgumentException异常。</font></p>
     * <pre><font color=green>
     * StringTools.abbreviate(null, *)      = null
     * StringTools.abbreviate("", 4)        = ""
     * StringTools.abbreviate("abcdefg", 6) = "abc..."
     * StringTools.abbreviate("abcdefg", 7) = "abcdefg"
     * StringTools.abbreviate("abcdefg", 8) = "abcdefg"
     * StringTools.abbreviate("abcdefg", 4) = "a..."
     * StringTools.abbreviate("abcdefg", 3) = IllegalArgumentException
     * </font></pre>
     *
     * @param str      待缩写字符串
     * @param maxWidth 缩写字符串的长度
     * @return 指定长度的缩写字符串；若字符串长度小于最大长度，则返回自身
     */
    public static String abbreviate(String str, int maxWidth) {
        return abbreviate(str, 0, maxWidth);
    }

    /**
     * <p>在给定的长度和偏移量内取得字符串的缩写（暂不开发，无相应应用场景）。</p>
     * <pre><font color=green>
     * StringTools.abbreviate(null, *, *)                = null
     * StringTools.abbreviate("", 0, 4)                  = ""
     * StringTools.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..."
     * StringTools.abbreviate("abcdefghijklmno", 0, 10)  = "abcdefg..."
     * StringTools.abbreviate("abcdefghijklmno", 1, 10)  = "abcdefg..."
     * StringTools.abbreviate("abcdefghijklmno", 4, 10)  = "abcdefg..."
     * StringTools.abbreviate("abcdefghijklmno", 5, 10)  = "...fghi..."
     * StringTools.abbreviate("abcdefghijklmno", 6, 10)  = "...ghij..."
     * StringTools.abbreviate("abcdefghijklmno", 8, 10)  = "...ijklmno"
     * StringTools.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno"
     * StringTools.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno"
     * StringTools.abbreviate("abcdefghij", 0, 3)        = IllegalArgumentException
     * StringTools.abbreviate("abcdefghij", 5, 6)        = IllegalArgumentException
     * </font></pre>
     *
     * @param str      待缩写字符串
     * @param offset   偏移量
     * @param maxWidth 缩写字符串的长度
     * @return 指定长度和偏移量的缩写字符串
     */
    private static String abbreviate(String str, int offset, int maxWidth) {
        if (str == null) {
            return null;
        }

        if (maxWidth < 4) {
            throw new IllegalArgumentException("Minimum abbreviation width is 4");
        }

        if (str.length() <= maxWidth) {
            return str;
        }

        if (offset > str.length()) {
            offset = str.length();
        }

        if (str.length() - offset < maxWidth - 3) {
            offset = str.length() - (maxWidth - 3);
        }

        final String abrevMarker = "...";

        if (offset <= 4) {
            return str.substring(0, maxWidth - 3) + abrevMarker;
        }

        if (maxWidth < 7) {
            throw new IllegalArgumentException("Minimum abbreviation width with offset is 7");
        }

        if (offset + maxWidth - 3 < str.length()) {
            return abrevMarker + abbreviate(str.substring(offset), maxWidth - 3);
        }

        return abrevMarker + str.substring(str.length() - (maxWidth - 3));
    }

    /**
     * <p>返回指定字符在此字符串中最后一次出现处的索引位置。</p>
     * <pre><font color=green>
     * StringTools.lastIndexOf(null, *)         = -1
     * StringTools.lastIndexOf("", *)           = -1
     * StringTools.lastIndexOf("aabaabaa", 'a') = 7
     * StringTools.lastIndexOf("aabaabaa", 'b') = 5
     * </font></pre>
     *
     * @param string     字符串
     * @param searchChar 指定字符
     * @return 返回指定字符在此字符串中最后一次出现处的索引，从指定的索引处开始进行反向搜索；若找不到则返回-1
     */
    public static int lastIndexOf(String string, char searchChar) {
        if (isEmpty(string)) {
            return -1;
        }

        return string.lastIndexOf(searchChar, string.length());
    }

    /**
     * <p>返回指定字符串在此字符串中最后一次出现处的索引位置。</p>
     * <pre><font color=green>
     * StringTools.lastIndexOf(null, *)          = -1
     * StringTools.lastIndexOf(*, null)          = -1
     * StringTools.lastIndexOf("", "")           = 0
     * StringTools.lastIndexOf("aabaabaa", "a")  = 7
     * StringTools.lastIndexOf("aabaabaa", "b")  = 5
     * StringTools.lastIndexOf("aabaabaa", "ab") = 4
     * StringTools.lastIndexOf("aabaabaa", "")   = 8
     * </font></pre>
     *
     * @param string     字符串
     * @param searchChar 指定字符
     * @return 返回指定字符串在此字符串中最后一次出现处的索引，从指定的索引处开始进行反向搜索
     */
    public static int lastIndexOf(String string, String searchChar) {
        if (isEmpty(string)) {
            return -1;
        }

        return string.lastIndexOf(searchChar, string.length());
    }

    /**
     * <p>是否包含指定字符。</p>
     * <pre><font color=green>
     * StringTools.contains(null, *)     = false
     * StringTools.contains(*, null)     = false
     * StringTools.contains("", "")      = true
     * StringTools.contains("abc", "")   = true
     * StringTools.contains("abc", "a")  = true
     * StringTools.contains("abc", "z")  = false
     * </font></pre>
     *
     * @param string     字符串
     * @param searchChar 指定字符
     * @return 如果包含指定字符，则返回{@code true}；否则返回{@code false}
     */
    public static boolean contains(String string, char searchChar) {
        if (isEmpty(string)) {
            return false;
        }

        return indexOf(string, searchChar, 0) >= 0;
    }

    /**
     * <p>是否包含空格字符。</p>
     * <pre><font color=green>
     * StringTools.containsWhitespace("ab c")  = true
     * StringTools.containsWhitespace("")  = false
     * StringTools.containsWhitespace(null)  = false
     * </font></pre>
     *
     * @param str 字符串
     * @return 如果包含空格字符，则返回{@code true}；否则返回{@code false}
     */
    public static boolean containsWhitespace(String str) {
        if (isEmpty(str)) {
            return false;
        }
        int strLen = str.length();
        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(str.charAt(i))) {
                return true;
            }
        }
        return false;
    }

    /**
     * <p>按照给定的字符拆分字符串。</p>
     * <pre><font color=green>
     * StringTools.splitToString("ab,bc",",")  = ["ab","bc"]
     * StringTools.splitToString("null",",")  = null
     * StringTools.splitToString("",",")  = []
     * </font></pre>
     *
     * @param string    待拆分字符串
     * @param charSplit 给定的拆分字符
     * @return 给定拆分字符拆分后的字符串数组；如果待拆分字符串为Null，则返回Null；如果待拆分字符串为空串，则返回长度为0的数组
     */
    public static String[] splitToString(String string, String charSplit) {
        if (string == null) {
            return null;
        }

        if (string.length() == 0) {
            return new String[0];
        }

        return string.split(charSplit);
    }

    /**
     * <p>按照给定的字符拆分字符串。</p>
     * <pre><font color=green>
     * StringTools.splitToLong("12,32",",")  = [12,32]
     * StringTools.splitToLong("null",",")  = null
     * StringTools.splitToLong("",",")  = []
     * StringTools.splitToLong("1,s",",")  = IllegalArgumentException
     * </font></pre>
     *
     * @param string    待拆分字符串
     * @param charSplit 给定的拆分字符
     * @return 给定拆分字符拆分后的长整型数组；如果待拆分字符串为Null，则返回Null；如果待拆分字符串为空串，则返回长度为0的数组
     */
    public static long[] splitToLong(String string, String charSplit) {
        String[] temp = splitToString(string, charSplit);

        if (temp == null) {
            return null;
        }

        if (temp.length == 0) {
            return new long[0];
        }

        long[] newArray = new long[temp.length];

        try {
            for (int i = 0; i < temp.length; i++) {
                newArray[i] = Long.parseLong(temp[i]);
            }
        } catch (Exception e) {
            throw new IllegalArgumentException("Input string is not number string.");
        }

        return newArray;
    }

    /**
     * <p>按照给定的字符拆分字符串。</p>
     * <pre><font color=green>
     * StringTools.splitToDouble("12.01,32",",")  = [12.01,32.0]
     * StringTools.splitToDouble("null",",")  = null
     * StringTools.splitToDouble("",",")  = []
     * StringTools.splitToDouble("1,s",",")  = IllegalArgumentException
     * </font></pre>
     *
     * @param string    待拆分字符串
     * @param charSplit 给定的拆分字符
     * @return 给定拆分字符拆分后的双精度型数组；如果待拆分字符串为Null，则返回Null；如果待拆分字符串为空串，则返回长度为0的数组
     */
    public static double[] splitToDouble(String string, String charSplit) {
        String[] temp = splitToString(string, charSplit);

        if (temp == null) {
            return null;
        }

        if (temp.length == 0) {
            return new double[0];
        }

        double[] newArray = new double[temp.length];

        try {
            for (int i = 0; i < temp.length; i++) {
                newArray[i] = Double.parseDouble(temp[i]);
            }
        } catch (Exception e) {
            throw new IllegalArgumentException("Input string is not number string.");
        }

        return newArray;
    }

    /**
     * <p>按照给定的字符拆分字符串。</p>
     * <pre><font color=green>
     * StringTools.splitToDouble("12.01,32",",")  = [12.01,32.0]
     * StringTools.splitToDouble("null",",")  = null
     * StringTools.splitToDouble("",",")  = []
     * StringTools.splitToDouble("1,s",",")  = IllegalArgumentException
     * </font></pre>
     *
     * @param string    待拆分字符串
     * @param charSplit 给定的拆分字符
     * @return 给定拆分字符拆分后的浮点型数组；如果待拆分字符串为Null，则返回Null；如果待拆分字符串为空串，则返回长度为0的数组
     */
    public static float[] splitToFloat(String string, String charSplit) {
        String[] temp = splitToString(string, charSplit);

        if (temp == null) {
            return null;
        }

        if (temp.length == 0) {
            return new float[0];
        }

        float[] newArray = new float[temp.length];

        try {
            for (int i = 0; i < temp.length; i++) {
                newArray[i] = Float.parseFloat(temp[i]);
            }
        } catch (Exception e) {
            throw new IllegalArgumentException("Input string is not number string.");
        }

        return newArray;
    }

    /**
     * <p>截取第一次匹配到的嵌套字符串。</p>
     * <pre><font color=green>
     * StringTools.substringBetween("wx[b]yz", "[", "]") = "b"
     * StringTools.substringBetween(null, *, *)          = null
     * StringTools.substringBetween(*, null, *)          = null
     * StringTools.substringBetween(*, *, null)          = null
     * StringTools.substringBetween("", "", "")          = ""
     * StringTools.substringBetween("", "", "]")         = null
     * StringTools.substringBetween("", "[", "]")        = null
     * StringTools.substringBetween("yabcz", "", "")     = ""
     * StringTools.substringBetween("yabcz", "y", "z")   = "abc"
     * StringTools.substringBetween("yabczyabcdz", "y", "z")   = "abc"
     * </font></pre>
     *
     * @param str   待截取字符串
     * @param open  开始字符串
     * @param close 结尾字符串
     * @return 开始字符串与结尾字符串之间的字符串；如果待截取字符串或开始字符串或结尾字符串为Null，则返回Null
     */
    public static String substringBetween(String str, String open, String close) {
        if (str == null || open == null || close == null) {
            return null;
        }

        int start = str.indexOf(open);
        if (start != -1) {
            int end = str.indexOf(close, start + open.length());
            if (end != -1) {
                return str.substring(start + open.length(), end);
            }
        }

        return null;
    }

    /**
     * <p>截取所有匹配到的嵌套字符串。</p>
     * <pre><font color=green>
     * StringTools.substringsBetween(null, *, *)            = null
     * StringTools.substringsBetween(*, null, *)            = null
     * StringTools.substringsBetween(*, *, null)            = null
     * StringTools.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"]
     * StringTools.substringsBetween("yabczyabcdz", "y", "z") = ["abc","abcd"]
     * </font></pre>
     *
     * @param str   待截取字符串
     * @param open  开始字符串
     * @param close 结尾字符串
     * @return 所有匹配到的开始字符串与结尾字符串之间的字符串数组；如果待截取字符串或开始字符串或结尾字符串为Null，则返回Null；若字符串为""，则返回长度0的数组
     */
    public static String[] substringsBetween(String str, String open, String close) {
        if (str == null || isEmpty(open) || isEmpty(close)) {
            return null;
        }

        int strLen = str.length();
        if (strLen == 0) {
            return new String[0];
        }

        int closeLen = close.length();
        int openLen = open.length();

        List<String> list = new ArrayList<String>();
        int pos = 0;
        while (pos < strLen - closeLen) {
            int start = str.indexOf(open, pos);

            if (start < 0) {
                break;
            }

            start += openLen;
            int end = str.indexOf(close, start);
            if (end < 0) {
                break;
            }

            list.add(str.substring(start, end));
            pos = end + closeLen;
        }

        if (list.isEmpty()) {
            return null;
        }

        return list.toArray(new String[list.size()]);
    }

    /**
     * <p>去除尾部换行符。</p>
     * <pre><font color=green>
     * StringTools.chomp(null)          = null
     * StringTools.chomp("")            = ""
     * StringTools.chomp("abc \r")      = "abc "
     * StringTools.chomp("abc\n")       = "abc"
     * StringTools.chomp("abc\r\n")     = "abc"
     * StringTools.chomp("abc\r\n\r\n") = "abc\r\n"
     * StringTools.chomp("abc\n\r")     = "abc\n"
     * StringTools.chomp("abc\n\rabc")  = "abc\n\rabc"
     * StringTools.chomp("\r")          = ""
     * StringTools.chomp("\n")          = ""
     * StringTools.chomp("\r\n")        = ""
     * </font></pre>
     *
     * @param str 待处理字符串
     * @return 去除尾部换行符后的字符串
     */
    public static String chomp(String str) {
        if (isEmpty(str)) {
            return str;
        }

        if (str.length() == 1) {
            char ch = str.charAt(0);
            if (ch == '\r' || ch == '\n') {
                return "";
            }
            return str;
        }

        int lastIdx = str.length() - 1;
        char last = str.charAt(lastIdx);

        if (last == '\n') {
            if (str.charAt(lastIdx - 1) == '\r') {
                lastIdx--;
            }
        } else if (last != '\r') {
            lastIdx++;
        }

        return str.substring(0, lastIdx);
    }

    /**
     * <p>移除字符串最后一个字符。</p>
     * <pre><font color=green>
     * StringTools.removeLastChar(null)          = null
     * StringTools.removeLastChar("")            = ""
     * StringTools.removeLastChar("abc \r")      = "abc "
     * StringTools.removeLastChar("abc\n")       = "abc"
     * StringTools.removeLastChar("abc\r\n")     = "abc"
     * StringTools.removeLastChar("abc")         = "ab"
     * StringTools.removeLastChar("abc\nabc")    = "abc\nab"
     * StringTools.removeLastChar("a")           = ""
     * StringTools.removeLastChar("\r")          = ""
     * StringTools.removeLastChar("\n")          = ""
     * StringTools.removeLastChar("\r\n")        = ""
     * </font></pre>
     *
     * @param str 待处理字符串
     * @return 移除字符串最后一个字符后的字符串
     */
    public static String removeLastChar(String str) {
        if (str == null) {
            return null;
        }

        int strLen = str.length();
        if (strLen < 2) {
            return "";
        }

        int lastIdx = strLen - 1;
        String ret = str.substring(0, lastIdx);
        char last = str.charAt(lastIdx);
        if (last == '\n' && ret.charAt(lastIdx - 1) == '\r') {
            return ret.substring(0, lastIdx - 1);
        }

        return ret;
    }

    /**
     * <p>重复字符串若干次。</p>
     * <pre><font color=green>
     * StringTools.repeat(null, 2) = null
     * StringTools.repeat("", 0)   = ""
     * StringTools.repeat("", 2)   = ""
     * StringTools.repeat("a", 3)  = "aaa"
     * StringTools.repeat("ab", 2) = "abab"
     * StringTools.repeat("a", -2) = ""
     * </font></pre>
     *
     * @param str    待重复字符串
     * @param repeat 重复次数
     * @return 返回字符串重复了若干次后的新字符串；如果重复次数小于等于0，则返回""
     */
    public static String repeat(String str, int repeat) {
        if (str == null) {
            return null;
        }
        if (repeat <= 0) {
            return "";
        }
        int inputLength = str.length();
        if (repeat == 1 || inputLength == 0) {
            return str;
        }
        if (inputLength == 1 && repeat <= 8192) {
            return repeat(str.charAt(0), repeat);
        }

        int outputLength = inputLength * repeat;
        switch (inputLength) {
            case 1:
                return repeat(str.charAt(0), repeat);
            case 2:
                char ch0 = str.charAt(0);
                char ch1 = str.charAt(1);
                char[] output2 = new char[outputLength];
                for (int i = repeat * 2 - 2; i >= 0; i--, i--) {
                    output2[i] = ch0;
                    output2[i + 1] = ch1;
                }
                return new String(output2);
            default:
                StringBuilder buf = new StringBuilder(outputLength);
                for (int i = 0; i < repeat; i++) {
                    buf.append(str);
                }
                return buf.toString();
        }
    }

    /**
     * <p>重复字符若干次。</p>
     * <pre><font color=green>
     * StringTools.repeat('e',0)  = ""
     * StringTools.repeat('e',3)  = "eee"
     * StringTools.repeat('e',-2) = ""
     * </font></pre>
     *
     * @param ch     待重复字符
     * @param repeat 重复次数
     * @return 返回字符重复了若干次后的新字符串
     */
    public static String repeat(char ch, int repeat) {
        char[] buf = new char[repeat];
        for (int i = repeat - 1; i >= 0; i--) {
            buf[i] = ch;
        }

        return new String(buf);
    }

    /**
     * <p>反转字符串。</p>
     * <pre><font color=green>
     * StringTools.reverse(null)  = null
     * StringTools.reverse("")    = ""
     * StringTools.reverse("bat") = "tab"
     * </font></pre>
     *
     * @param str 待反转字符串，可能为null
     * @return 反转后的字符串
     */
    public static String reverse(String str) {
        if (str == null) {
            return null;
        }

        return new StringBuilder(str).reverse().toString();
    }

    /**
     * <p>检查字符串是否全部由数字组成。</p>
     * <pre><font color=green>
     * StringTools.isNumeric(null)   = false
     * StringTools.isNumeric("")     = false
     * StringTools.isNumeric("  ")   = false
     * StringTools.isNumeric("123")  = true
     * StringTools.isNumeric("12 3") = false
     * StringTools.isNumeric("ab2c") = false
     * StringTools.isNumeric("12-3") = false
     * StringTools.isNumeric("12.3") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串全部由数字组成，返回{@code true}；否则返回{@code false}
     */
    public static boolean isNumeric(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isDigit(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串是否全部由数字或者空格组成。</p>
     * <pre><font color=green>
     * StringTools.isNumericOrSpace(null)   = false
     * StringTools.isNumericOrSpace("")     = true
     * StringTools.isNumericOrSpace("  ")   = true
     * StringTools.isNumericOrSpace("123")  = true
     * StringTools.isNumericOrSpace("12 3") = true
     * StringTools.isNumericOrSpace("ab2c") = false
     * StringTools.isNumericOrSpace("12-3") = false
     * StringTools.isNumericOrSpace("12.3") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串全部由数字或者空格组成，返回{@code true}；否则返回{@code false}
     */
    public static boolean isNumericOrSpace(String str) {
        if (str == null) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isDigit(str.charAt(i)) == false && str.charAt(i) != ' ') {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串是否全部由字母组成。</p>
     * <pre><font color=green>
     * StringTools.isAlpha(null)   = false
     * StringTools.isAlpha("")     = false
     * StringTools.isAlpha("  ")   = false
     * StringTools.isAlpha("abc")  = true
     * StringTools.isAlpha("ab2c") = false
     * StringTools.isAlpha("ab-c") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串全部由字母组成，返回{@code true}；否则返回{@code false}
     */
    public static boolean isAlpha(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isLetter(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串是否全部由字母或者空格组成。</p>
     * <pre><font color=green>
     * StringTools.isAlphaOrSpace(null)   = false
     * StringTools.isAlphaOrSpace("")     = true
     * StringTools.isAlphaOrSpace("  ")   = true
     * StringTools.isAlphaOrSpace("abc")  = true
     * StringTools.isAlphaOrSpace("ab c") = true
     * StringTools.isAlphaOrSpace("ab2c") = false
     * StringTools.isAlphaOrSpace("ab-c") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串全部由字母或者空格组成，返回{@code true}；否则返回{@code false}
     */
    public static boolean isAlphaOrSpace(String str) {
        if (str == null) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isLetter(str.charAt(i)) == false && str.charAt(i) != ' ') {
                return false;
            }
        }

        return true;
    }


    /**
     * <p>检查字符串是否全部由字母或者数字组成。</p>
     * <pre><font color=green>
     * StringTools.isAlphaOrNumeric(null)   = false
     * StringTools.isAlphaOrNumeric("")     = false
     * StringTools.isAlphaOrNumeric("  ")   = false
     * StringTools.isAlphaOrNumeric("abc")  = true
     * StringTools.isAlphaOrNumeric("ab c") = false
     * StringTools.isAlphaOrNumeric("ab2c") = true
     * StringTools.isAlphaOrNumeric("ab-c") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串全部由字母或者数字组成, 则返回{@code true}；否则返回{@code false}
     */
    public static boolean isAlphaOrNumeric(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isLetterOrDigit(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串是否全部由字母或者数字或者空格组成。</p>
     * <pre><font color=green>
     * StringTools.isAlphaOrNumericOrSpace(null)   = false
     * StringTools.isAlphaOrNumericOrSpace("")     = true
     * StringTools.isAlphaOrNumericOrSpace("  ")   = true
     * StringTools.isAlphaOrNumericOrSpace("abc")  = true
     * StringTools.isAlphaOrNumericOrSpace("ab c") = true
     * StringTools.isAlphaOrNumericOrSpace("ab2c") = true
     * StringTools.isAlphaOrNumericOrSpace("ab-c") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串全部由字母或者数字或者空格组成, 则返回{@code true}；否则返回{@code false}
     */
    public static boolean isAlphaOrNumericOrSpace(String str) {
        if (str == null) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isLetterOrDigit(str.charAt(i)) == false && str.charAt(i) != ' ') {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串是否只包含空格字符。</p>
     * <pre><font color=green>
     * StringTools.isWhitespace(null)   = false
     * StringTools.isWhitespace("")     = true
     * StringTools.isWhitespace("  ")   = true
     * StringTools.isWhitespace("abc")  = false
     * StringTools.isWhitespace("ab2c") = false
     * StringTools.isWhitespace("ab-c") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串全部由空格组成，返回{@code true}；否则返回{@code false}
     */
    public static boolean isWhitespace(String str) {
        if (str == null) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isWhitespace(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串里字符是否都是小写。</p>
     * <pre><font color=green>
     * StringTools.isAllLowerCase(null)   = false
     * StringTools.isAllLowerCase("")     = false
     * StringTools.isAllLowerCase("  ")   = false
     * StringTools.isAllLowerCase("abc")  = true
     * StringTools.isAllLowerCase("abC") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串中的字符全部是小写，返回{@code true}；否则，返回{@code false}
     */
    public static boolean isAllLowerCase(String str) {
        if (str == null || isEmpty(str)) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isLowerCase(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>检查字符串里字符是否都是大写。</p>
     * <pre><font color=green>
     * StringTools.isAllUpperCase(null)   = false
     * StringTools.isAllUpperCase("")     = false
     * StringTools.isAllUpperCase("  ")   = false
     * StringTools.isAllUpperCase("ABC")  = true
     * StringTools.isAllUpperCase("aBC") = false
     * </font></pre>
     *
     * @param str 待检查字符串
     * @return 如果字符串中的字符全部是大写，返回{@code true}；否则，返回{@code false}
     */
    public static boolean isAllUpperCase(String str) {
        if (str == null || isEmpty(str)) {
            return false;
        }

        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isUpperCase(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }

    /**
     * <p>查找某个字符串在另一个字符串中出现的次数。</p>
     * <pre><font color=green>
     * StringTools.countMatches(null, *)       = 0
     * StringTools.countMatches("", *)         = 0
     * StringTools.countMatches("abba", null)  = 0
     * StringTools.countMatches("abba", "")    = 0
     * StringTools.countMatches("abba", "a")   = 2
     * StringTools.countMatches("abba", "ab")  = 1
     * StringTools.countMatches("abba", "xxx") = 0
     * </font></pre>
     *
     * @param str       源字符串
     * @param searchStr 待查找字符串
     * @return 待查找字符串在源字符串出现的次数
     */
    public static int countMatches(String str, String searchStr) {
        if (isEmpty(str) || isEmpty(searchStr)) {
            return 0;
        }

        int count = 0;
        int idx = 0;
        while ((idx = indexOf(str, searchStr, idx)) != -1) {
            count++;
            idx += searchStr.length();
        }

        return count;
    }

    /**
     * <p>首字母大写。</p>
     * <pre><font color=green>
     * StringTools.firstToUpperCase(null)  = null
     * StringTools.firstToUpperCase("")    = ""
     * StringTools.firstToUpperCase("cat") = "Cat"
     * StringTools.firstToUpperCase("cAt") = "CAt"
     * </font></pre>
     *
     * @param str 待处理字符串
     * @return 首字母大写后的字符串
     */
    public static String firstToUpperCase(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        return new StringBuilder(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1)).toString();
    }

    /**
     * <p>首字母小写。</p>
     * <pre><font color=green>
     * StringTools.firstToLowerCase(null)  = null
     * StringTools.firstToLowerCase("")    = ""
     * StringTools.firstToLowerCase("Cat") = "cat"
     * StringTools.firstToLowerCase("CAT") = "cAT"
     * </font></pre>
     *
     * @param str 待处理字符串
     * @return 首字母小写后的字符串
     */
    public static String firstToLowerCase(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        return new StringBuilder(strLen).append(Character.toLowerCase(str.charAt(0))).append(str.substring(1)).toString();
    }

    /**
     * <p>若不足指定长度，字符串左补位某个字符。</p>
     * <pre><font color=green>
     * StringTools.leftPad(null, *, *)     = null
     * StringTools.leftPad("", 3, 'z')     = "zzz"
     * StringTools.leftPad("bat", 3, 'z')  = "bat"
     * StringTools.leftPad("bat", 5, '*')  = "**bat"
     * StringTools.leftPad("bat", 1, 'z')  = "bat"
     * StringTools.leftPad("bat", -1, 'z') = "bat"
     * </font></pre>
     *
     * @param str     待补位字符串
     * @param size    指定字符串长度
     * @param padChar 补位字符
     * @return 字符串或者补位后的字符串
     */
    public static String leftPad(String str, int size, char padChar) {
        if (str == null) {
            return null;
        }

        int pads = size - str.length();
        if (pads <= 0) {
            return str;
        }

        if (pads > 8192) {
            return leftPad(str, size, String.valueOf(padChar));
        }

        return repeat(padChar, pads).concat(str);
    }

    /**
     * <p>若不足指定长度，字符串左补位某个字符串。</p>
     * <pre><font color=green>
     * StringTools.leftPad(null, *, *)      = null
     * StringTools.leftPad("", 3, "z")      = "zzz"
     * StringTools.leftPad("bat", 3, "yz")  = "bat"
     * StringTools.leftPad("bat", 5, "**")  = "**bat"
     * StringTools.leftPad("bat", 8, "yz")  = "yzyzybat"
     * StringTools.leftPad("bat", 1, "yz")  = "bat"
     * StringTools.leftPad("bat", -1, "yz") = "bat"
     * StringTools.leftPad("bat", 5, null)  = "  bat"
     * StringTools.leftPad("bat", 5, "")    = "  bat"
     * </font></pre>
     *
     * @param str    待补位字符串
     * @param size   指定字符串长度
     * @param padStr 补位字符
     * @return 字符串或者补位后的字符串
     */
    public static String leftPad(String str, int size, String padStr) {
        if (str == null) {
            return null;
        }

        if (isEmpty(padStr)) {
            padStr = " ";
        }

        int padLen = padStr.length();
        int strLen = str.length();
        int pads = size - strLen;
        if (pads <= 0) {
            return str;
        }

        if (padLen == 1 && pads <= 8192) {
            return leftPad(str, size, padStr.charAt(0));
        }

        if (pads == padLen) {
            return padStr.concat(str);
        } else if (pads < padLen) {
            return padStr.substring(0, pads).concat(str);
        } else {
            char[] padding = new char[pads];
            char[] padChars = padStr.toCharArray();
            for (int i = 0; i < pads; i++) {
                padding[i] = padChars[i % padLen];
            }
            return new String(padding).concat(str);
        }
    }

    /**
     * <p>若不足指定长度，字符串右补位某个字符。</p>
     * <pre><font color=green>
     * StringTools.rightPad(null, *, *)     = null
     * StringTools.rightPad("", 3, 'z')     = "zzz"
     * StringTools.rightPad("bat", 3, 'z')  = "bat"
     * StringTools.rightPad("bat", 5, '*')  = "bat**"
     * StringTools.rightPad("bat", 1, 'z')  = "bat"
     * StringTools.rightPad("bat", -1, 'z') = "bat"
     * </font></pre>
     *
     * @param str     待补位字符串
     * @param size    指定字符串长度
     * @param padChar 补位字符
     * @return 字符串或者补位后的字符串
     */
    public static String rightPad(String str, int size, char padChar) {
        if (str == null) {
            return null;
        }

        int pads = size - str.length();
        if (pads <= 0) {
            return str;
        }

        if (pads > 8192) {
            return rightPad(str, size, String.valueOf(padChar));
        }

        return str.concat(repeat(padChar, pads));
    }

    /**
     * <p>若不足指定长度，字符串右补位某个字符。</p>
     * <pre><font color=green>
     * StringTools.rightPad(null, *, *)      = null
     * StringTools.rightPad("", 3, "z")      = "zzz"
     * StringTools.rightPad("bat", 3, "yz")  = "bat"
     * StringTools.rightPad("bat", 5, "*")  = "bat**"
     * StringTools.rightPad("bat", 8, "yz")  = "batyzyzy"
     * StringTools.rightPad("bat", 1, "yz")  = "bat"
     * StringTools.rightPad("bat", -1, "yz") = "bat"
     * StringTools.rightPad("bat", 5, null)  = "bat  "
     * StringTools.rightPad("bat", 5, "")    = "bat  "
     * </font></pre>
     *
     * @param str    待补位字符串
     * @param size   指定字符串长度
     * @param padStr 补位字符串
     * @return 字符串或者补位后的字符串
     */
    public static String rightPad(String str, int size, String padStr) {
        if (str == null) {
            return null;
        }

        if (isEmpty(padStr)) {
            padStr = " ";
        }

        int padLen = padStr.length();
        int strLen = str.length();
        int pads = size - strLen;
        if (pads <= 0) {
            return str;
        }

        if (padLen == 1 && pads <= 8192) {
            return rightPad(str, size, padStr.charAt(0));
        }

        if (pads == padLen) {
            return str.concat(padStr);
        } else if (pads < padLen) {
            return str.concat(padStr.substring(0, pads));
        } else {
            char[] padding = new char[pads];
            char[] padChars = padStr.toCharArray();
            for (int i = 0; i < pads; i++) {
                padding[i] = padChars[i % padLen];
            }
            return str.concat(new String(padding));
        }
    }

    /**
     * <p>检查字符串数组中是否包含有空对象。</p>
     * <pre><font color=green>
     * StringTools.containNull(null, "test")      = true
     * StringTools.containNull("s","test")      = false
     * </font></pre>
     *
     * @param args 待检查字符串数组
     * @return 如果字符串数组中含有null对象，则返回{@code true}；否则返回{@code false}
     */
    public static boolean containNull(String... args) {
        for (String str : args) {
            if (str == null) {
                return true;
            }
        }

        return false;
    }

    /**
     * <p>按照分隔符组装字符串。</p>
     * <pre><font color=green>
     * StringTools.join(["a","b"], ",")      = "a,b"
     * StringTools.join(["a","b"], null)      = "a,b"
     * </font></pre>
     *
     * @param strs      待组装字符串的数组，若str为Null或者大小为0则返回Null
     * @param splitChar 分隔符，若splitChar为Null则默认采用','
     * @return 组装的字符串
     */
    public static String join(String[] strs, String splitChar) {
        if (strs == null || strs.length == 0) {
            return null;
        }

        if (splitChar == null) {
            splitChar = ",";
        }

        String value = null;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strs.length; i++) {
            sb.append(strs[i]).append(splitChar);
        }

        value = sb.toString();
        if (value.endsWith(splitChar)) {
            value = value.substring(0, value.length() - 1);
        }

        return value;
    }

    /**
     * <p>验证字符串合法性。</p>
     * <pre><font color=green>
     * StringTools.check("sfs@","@")      = false
     * StringTools.check("sfdfsf","@")      = true
     * </font></pre>
     *
     * @param str  需要验证的字符串，若为空串或Null则返回false
     * @param test 非法字符串（如："~!#$%^&*()',;:?"），若为空串或Null则返回true
     * @return {@code true}-合法;{@code false}-非法
     */
    public static boolean check(String str, String test) {
        if (isEmpty(str)) {
            return false;
        }

        if (isEmpty(test)) {
            return true;
        }

        boolean flag = false;
        for (int i = 0; i < test.length(); i++) {
            if (str.indexOf(test.charAt(i)) != -1) {
                flag = false;
                break;
            }
        }

        return flag;
    }

    /**
     * <p>将阿拉伯数字的钱数转换成中文方式(有BUG,数值大了以后不能正确显示，需修复)。</p>
     * <pre><font color=green>
     * StringTools.num2Chinese(1092.1251) = 一千零九十二元一角三分
     * </font></pre>
     *
     * @param num 需要转换的钱的阿拉伯数字形式，支持到小数点后2位，若超过将四舍五入
     * @return 转换后的中文形式
     */
    @Deprecated
    private static String num2Chinese(double num) {
        DecimalFormat df = new DecimalFormat(".##");
        num = Double.parseDouble(df.format(num));

        String result = "";
        String str = Double.toString(num);
        if (str.contains(".")) {
            String begin = str.substring(0, str.indexOf("."));
            String end = str.substring(str.indexOf(".") + 1, str.length());
            byte[] b = begin.getBytes();
            int j = b.length;
            for (int i = 0, k = j; i < j; i++, k--) {
                result += getConvert(begin.charAt(i));
                if (!"零".equals(result.charAt(result.length() - 1) + "")) {
                    result += getWei(k);
                }
            }
            for (int i = 0; i < result.length(); i++) {
                result = result.replaceAll("零零", "零");
            }
            if ("零".equals(result.charAt(result.length() - 1) + "")) {
                result = result.substring(0, result.length() - 1);
            }
            result += "元";
            byte[] bb = end.getBytes();
            int jj = bb.length;
            for (int i = 0, k = jj; i < jj; i++, k--) {
                result += getConvert(end.charAt(i));
                if (bb.length == 1) {
                    result += "角";
                } else if (bb.length == 2) {
                    result += getFloat(k);
                }
            }
        } else {
            byte[] b = str.getBytes();
            int j = b.length;
            for (int i = 0, k = j; i < j; i++, k--) {
                result += getConvert(str.charAt(i));
                result += getWei(k);
            }
        }
        return result;
    }

    /**
     * <p>数字表现形式转换。</p>
     *
     * @param num 阿拉伯数字
     * @return 中文数字
     */
    private static String getConvert(char num) {
        if (num == '0') {
            return "零";
        } else if (num == '1') {
            return "一";
        } else if (num == '2') {
            return "二";
        } else if (num == '3') {
            return "三";
        } else if (num == '4') {
            return "四";
        } else if (num == '5') {
            return "五";
        } else if (num == '6') {
            return "六";
        } else if (num == '7') {
            return "七";
        } else if (num == '8') {
            return "八";
        } else if (num == '9') {
            return "九";
        } else {
            return "";
        }
    }

    /**
     * <p>单位表现形式转换。</p>
     *
     * @param num 阿拉伯数字
     * @return 中文钱表示形式
     */
    private static String getFloat(int num) {
        if (num == 2) {
            return "角";
        } else if (num == 1) {
            return "分";
        } else {
            return "";
        }
    }

    /**
     * <p>单位表现形式转换。</p>
     *
     * @param num 阿拉伯数字
     * @return 中文单位
     */
    private static String getWei(int num) {
        if (num == 1) {
            return "";
        } else if (num == 2) {
            return "十";
        } else if (num == 3) {
            return "百";
        } else if (num == 4) {
            return "千";
        } else if (num == 5) {
            return "万";
        } else if (num == 6) {
            return "十";
        } else if (num == 7) {
            return "百";
        } else if (num == 8) {
            return "千";
        } else if (num == 9) {
            return "亿";
        } else if (num == 10) {
            return "十";
        } else if (num == 11) {
            return "百";
        } else if (num == 12) {
            return "千";
        } else if (num == 13) {
            return "兆";
        } else {
            return "";
        }
    }

}
